package com.starview.star.operators;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class Builtins
{
  private static final Map<String, ICafeBuiltinVar> builtinVars = new HashMap<String, ICafeBuiltinVar>();

  public static Method findCafeEnter(String name)
  {
    ICafeBuiltin builtin = Intrinsics.getBuiltin(name);
    if (builtin != null)
      return findCafeEnter(builtin);
    return null;
  }

  public static Method findCafeEnter(ICafeBuiltin builtin)
  {
    for (Method m : builtin.getImplClass().getMethods()) {
      if (m.isAnnotationPresent(CafeEnter.class))
        return m;
    }

    return null;
  }

  public static boolean isBuiltinVar(String name)
  {
    return builtinVars.containsKey(name);
  }

  public static ICafeBuiltinVar getBuiltinVar(String name)
  {
    return builtinVars.get(name);
  }
}
